/******************************************************************************
This .do file produces the results in Online Appendix B pertaining to Belgian respondents
Table OB1 and Figure OB6
******************************************************************************/

clear
use "ess_cleaned_whole.dta"
set more off

*Restrict to citizens
keep if citizen == 1

/*********************************
Weights
*********************************/

gen anweight = pspwght*pweight
label var anweight "Analysis Weight"
*Note: svyset is not used because mixed does not work with svy: in this version of Stata. 

/*********************************
Labelling
*********************************/

label var self_te "Self Transcendence vs. Self-Enhancement"
label var cons_open "Conservation vs. Openness"
label var age "Age"
label var gender "Gender"
label def gend 1 "Female" 0 "Male"
label values gender gend

recode born_when (1=1 "Born in Country") (2 3 4 = 2 "Came to Country <20 Yrs Ago") (5 = 3 "Came to Country 20+ Yrs Ago"), gen(born_when1)
label var born_when1 "Born in Country?"

recode minority (0=1 "Minority Group") (1=0 "Non-Minority"), gen(minority1)
label var minority1 "Member of Minority?"

recode edulvla (55=.)
label var edulvla "Own Education"
label def ed 0 "Other Ed Level"  1 "< Lower Secondary" 2 "Lower Secondary" 3 "Upper Secondary" 4 "Post-Secondary, Non-Tertiary" 5 "Tertiary Education"
label values edulvla ed

recode edulvlfa (55=.)
label var edulvlfa "Father's Education"
label val edulvlfa ed

recode union (1 = 0 "Never a Union Member") (2 3 = 1 "Currently/Previously in Union"), gen(union1)
label var union1 "Union Membership"

label var socialtrust "Interpersonal Trust"
label var sclmeet "Freq of Social Interactions"
label var religiosity "Religiosity"
label var yrlvdae "Residential Stability"

label def dom 1 "Big City" 2 "Suburbs" 3 "Small City" 4 "Country Village" 5 "Countryside" 
label values domicil dom

label var post_soviet "Socialist Country?"
label def pos 1 "Socialist Country" 0 "Non-Socialist Country"
label values post_soviet pos

label var demyrs_01 "Years of Democracy"
label var ethnic_01 "Ethnic Heterogeneity"

gen belgium = 0
replace belgium = 1 if cntry == "BE"
label var belgium "Belgium?"
label def belg 1 "Belgian Respondent" 0 "Non-Belgian Respondent"
label values belgium belg


/*********************************
Rescaling Continuous Variables to 0-1 Scale
*********************************/

foreach var in support_others vote_elections obey opinions volunteer beactive self_te cons_open age socialtrust sclmeet religiosity yrlvdae {
	summ `var'
	replace `var' = (`var' - r(min))/(r(max)-r(min))
}

/*********************************
Higher Values in Belgium? 
*********************************/

*Multilevel model
eststo clear
foreach var in vote_elections obey support_others opinions volunteer beactive {
	eststo: mixed `var' i.belgium i.post_soviet demyrs_01 ethnic_01 || cntry: 
	}
esttab using belgian_mean.rtf, replace label se b(2) aic bic onecell ///
	title("{\b Table X}: Average Norm Support: Belgians vs. Other Europeans") ///
	addnote("Models use survey weights. Value orientation slopes are allowed to vary across countries. All continuous variables are scaled to range from 0-1.") ///
	mtitles("Vote" "Obey" "Support" "Opinions" "Volunteer" "Be Active") nobaselevels
eststo clear 

*Regression model on country means
preserve 
collapse (mean) vote_elections obey support_others opinions volunteer beactive belgium post_soviet demyrs_01 ethnic_01, by(cntry)
foreach var in vote_elections obey support_others opinions volunteer beactive {
	eststo: regress `var' i.belgium i.post_soviet demyrs_01 ethnic_01
	}
esttab using belgian_mean1.rtf, replace se b(2) aic bic onecell ///
	title("{\b Table X}: Average Norm Support: Belgians vs. Other Europeans") ///
	mtitles("Vote" "Obey" "Support" "Opinions" "Volunteer" "Be Active") nobaselevels label 
restore	
	
	
/*********************************
No Belgium
*********************************/
foreach var in vote_elections obey support_others opinions volunteer beactive  {
	local m2 " age i.gender i.minority1 i.union1 i.edulvla ib1.edulvlfa i.born_when1 i.post_soviet demyrs_01 ethnic_01"
	local m3 " age i.gender i.minority1 i.union1 i.edulvla ib1.edulvlfa i.born_when1 socialtrust sclmeet religiosity yrlvdae i.post_soviet demyrs_01 ethnic_01 "
	eststo clear
	eststo: mixed `var' self_te cons_open if belgium==0 [pweight=anweight] || country: self_te cons_open,  stddev
		parmest, label format(estimate min95 max95 p) list(parm label estimate min95 max95 p) saving(`var'1_nobelgium.dta, replace)
	eststo: mixed `var' self_te cons_open `m2' if belgium==0 [pweight=anweight] || country: self_te cons_open,  stddev
		parmest, label format(estimate min95 max95 p) list(parm label estimate min95 max95 p) saving(`var'2_nobelgium.dta, replace)
	eststo: mixed `var' self_te cons_open `m3' if belgium==0 [pweight=anweight] || country: self_te cons_open,  stddev
		parmest, label format(estimate min95 max95 p) list(parm label estimate min95 max95 p) saving(`var'3_nobelgium.dta, replace)
	esttab using `var'_nobelgium.rtf, replace label se b(2) aic bic onecell transform(ln*: exp(@) exp(@)) ///
		addnote("Models use survey weights. Value orientation slopes are allowed to vary across countries. All continuous variables are scaled to range from 0-1.") ///
		mtitles("Model 1" "Model 2" "Model 3") ///
		title("{\b Table X}: Value Orientations and `var' (No Belgian Respondents") ///
	order(self_te cons_open age 0.gender 1.gender 0.minority1 1.minority1 0.union1 1.union1 1.edulvla 2.edulvla 3.edulvla 4.edulvla 5.edulvla ///
		1.edulvlfa 2.edulvlfa 3.edulvlfa 4.edulvlfa 5.edulvlfa 0.edulvlfa 1.born_when1 2.born_when1 3.born_when1 socialtrust sclmeet religiosity yrlvdae 0.post_soviet 1.post_sovet demyrs_01 ethnic_01)
	}



	
	